package com.mvp.lt.airlineview.start;
import com.mvp.lt.airlineview.base.BaseActivity;
import android.animation.Animator;
import android.annotation.TargetApi;
import android.content.Intent;
import android.os.Build;
import android.os.Bundle;
import android.view.ViewAnimationUtils;
import android.view.ViewGroup;
import android.widget.TextView;

import androidx.annotation.Nullable;

import com.mvp.lt.airlineview.R;
import com.mvp.lt.airlineview.utils.LogUtil;
import com.mvp.lt.airlineview.utils.RxTimerUtil;
import com.mvp.lt.airlineview.HomeActivity;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import io.reactivex.disposables.Disposable;


/**
 * $activityName
 *
 * @author LiuTao
 * @date 2019/3/6/006
 */
public class WelcomeActivity extends BaseActivity {
    @BindView(R.id.welcome_text)
    TextView mWelcomeText;
    @BindView(R.id.welcome_main)
    ViewGroup mWelcomeMain;
    private String TAG = WelcomeActivity.class.getSimpleName();
    private RxTimerUtil mRxTimerUtil;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_welcome);
        ButterKnife.bind(this);
        mWelcomeMain.setBackgroundDrawable(getResources().getDrawable(R.drawable.welcon_bg));
        mRxTimerUtil = new RxTimerUtil();
        mRxTimerUtil.countTime(5, new RxTimerUtil.OnRxTimerListener() {
            @Override
            public void onSubscribe(Disposable d) {

            }

            @Override
            public void onNext(Integer integer) {
                LogUtil.e(TAG, integer + "");
                updateWelcomeText(integer);
            }

            @Override
            public void onError(Throwable throwable) {

            }

            @Override
            public void onComplete() {
                startActivity(new Intent(WelcomeActivity.this, HomeActivity.class));
                mRxTimerUtil.clearCountDownTime();
                finish();
            }
        });

        mWelcomeMain.post(new Runnable() {
            @TargetApi(Build.VERSION_CODES.LOLLIPOP)
            @Override
            public void run() {
                Animator circularReveal = ViewAnimationUtils.createCircularReveal(mWelcomeMain, mWelcomeMain.getWidth() / 2, mWelcomeMain.getHeight() / 2, 0, mWelcomeMain.getWidth());
                circularReveal.setDuration(2000);
                circularReveal.addListener(new Animator.AnimatorListener() {
                    @Override
                    public void onAnimationStart(Animator animator) {

                    }

                    @Override
                    public void onAnimationEnd(Animator animator) {
                        //greenChannel表示跳过拦截器验证

                    }

                    @Override
                    public void onAnimationCancel(Animator animator) {

                    }

                    @Override
                    public void onAnimationRepeat(Animator animator) {

                    }
                });
                circularReveal.start();
            }
        });
    }

    private void updateWelcomeText(int time) {
        mWelcomeText.setText("development by 刘涛 \n" + "跳过 | " + time);
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        if (mRxTimerUtil != null) {
            mRxTimerUtil.clearCountDownTime();
        }
        LogUtil.e(TAG, "------onDestroy------");
    }

    @OnClick(R.id.welcome_text)
    public void onViewClicked() {
        startActivity(new Intent(WelcomeActivity.this, HomeActivity.class));
        mRxTimerUtil.clearCountDownTime();
        finish();
    }


}
